//
//  IWFriendshipListViewController.m
//  ItcastWeibo
//
//  Created by mj on 14-1-15.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import "IWFriendshipListViewController.h"
#import "IWFriendshipCell.h"
#import "IWFriendshipParam.h"
#import "IWFriendshipResult.h"
#import "AyDefine.h"
@interface IWFriendshipListViewController ()

@end

@implementation IWFriendshipListViewController

- (void)viewDidLoad
{
    _header = [MJRefreshHeaderView header];
    _header.delegate = self;
    _header.scrollView = self.tableView;
    [_header beginRefreshing];
    
    _footer = [MJRefreshFooterView footer];
    _footer.delegate = self;
    _footer.scrollView = self.tableView;
    
    
    _friendships = [NSMutableArray array];
    _param = [[IWFriendshipParam alloc] init];
    
    [super viewDidLoad];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundView = nil;
    self.view.backgroundColor = IWGlobalBg;
    self.tableView.contentInset=UIEdgeInsetsMake(8, 0, 0, 0);
}

- (void)viewDidAppear:(BOOL)animated {}

- (void)dealloc
{
    [_header free];
    [_footer free];
}


#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (_result.total_number == _friendships.count || _result.next_cursor == 0) {
        _footer.hidden = YES;
    } else {
        _footer.hidden = NO;
    }
    return _friendships.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    IWFriendshipCell *cell = [IWFriendshipCell cellWithTableView:tableView];
    
    cell.user = _friendships[indexPath.row];
    
    cell.indexPath = indexPath;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [IWFriendshipCell cellHeight];
}

@end
